package com.changgou.business.listener;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

@Component
public class AdListener {

    @Autowired
    private RestTemplate restTemplate;
    //1 rabbitMq 接收广告信息改变
    //2 接收到消息以后发送消息
    //http://192.168.200.128/ad_update?position=web_index_lb
    @RabbitListener(queues = "AD_UPDATE_QUEUE")
    public void receiveMessage(String position){
        System.out.println("接收到的消息:"+position);
        String url="http://192.168.200.128/ad_update?position="+position;
        ResponseEntity<Map> responseEntity = restTemplate.getForEntity(url, Map.class);
        Map body = responseEntity.getBody();
        System.out.println(body);
    }
}
